#include <cstdio>
#include <malloc.h>

struct TNode 
{ 
struct TNode *left, *right; 
int size; 
int key; 
}*null; 

void Left_Rotate( struct TNode **t ) 
{ 
struct TNode *k = (*t)->right; 
(*t)->right = k->left; 
k->left = *t; 
k->size = (*t)->size; 
(*t)->size = (*t)->right->size + (*t)->left->size + 1; 
*t = k; 
} 

void Right_Rotate( struct TNode **t ) 
{ 
struct TNode *k = (*t)->left; 
(*t)->left = k->right; 
k->right = *t; 
k->size = (*t)->size; 
(*t)->size = (*t)->left->size + (*t)->right->size + 1; 
*t = k; 
} 

void Maintain( struct TNode **t, int flag ) 
{ 
if ( *t == null ) 
return ; 
if ( flag ) 
{ 
if ( (*t)->left == null ) 
return ; 
if ( (*t)->left->left->size > (*t)->right->size ) 
Right_Rotate( t ); 
else if ( (*t)->left->right->size > (*t)->right->size ) 
{ 
Left_Rotate( &(*t)->left ); 
Right_Rotate( t ); 
} 
else 
return ; 
} 
else 
{ 
if ( (*t)->right == null ) 
return ; 
if ( (*t)->right->right->size > (*t)->left->size ) 
Left_Rotate( t ); 
else if ( (*t)->right->left->size > (*t)->left->size ) 
{ 
Right_Rotate( &(*t)->right ); 
Left_Rotate( t ); 
} 
else 
return ; 
} 
Maintain( &(*t)->left, 1 ); 
Maintain( &(*t)->right, 0 ); 
Maintain( t, 0 ); 
Maintain( t, 1 ); 
} 

int Insert( struct TNode **t, const int x ) 
{ 
int tmp = 0; 
if ( *t == null ) 
{ 
*t = ( struct TNode * )malloc( sizeof( struct TNode ) ); 
(*t)->size = 1; 
(*t)->left = (*t)->right = null; 
(*t)->key = x; 
return 1; 
} 
else 
{ 
if ( x < (*t)->key ) 
tmp = Insert( &(*t)->left, x ); 
else 
tmp = Insert( &(*t)->right, x ); 
if ( tmp ) 
{ 
(*t)->size++; 
Maintain( t, x < (*t)->key ); 
} 
return tmp; 
} 
} 

TNode *head;

void print( TNode *p )
{
    if ( p == null )
        return ;
    print( p->left );
    printf("%d ", p->key);
    print( p->right );
}

int query( int q )
{
    TNode *s = head;
    while ( q != s->left->size + 1 )
    {
        if ( q > s->left->size + 1 )
        {
            q -= s->left->size + 1;
            s = s->right;
        }
        else
            s = s->left;
    }
    return s->key;
}

int main( )
{
    int t, cas, n, i, p;
//    freopen("out.txt", "w", stdout);
    null = ( struct TNode * )malloc( sizeof( struct TNode ) ); 
    null->size = 0;
    scanf("%d", &t);
    while ( t-- )
    {
        scanf("%d%d" ,&cas, &n);
        head = null;
        printf("%d %d\n", cas, n / 2 + 1);
        for ( i = 0; i < n; i++ )
        {
            scanf("%d", &p);
            Insert( &head, p );
            if ( !( i & 1 ) )
            {
                if ( i % 20 != 0 )
                    printf(" ");
                if ( i % 20 == 0 && i != 0 )
                    printf("\n");
                printf("%d", query( i / 2 + 1 ));
            }
        }
        printf("\n");
//        print( head );
    }
    return 0;
}